/**
 *行政区域删除
 */
'use strict';

const conn = require('../../libs/DB/Conn');
const _ = require('underscore');
const operationRecord = require("../sys/operationRecordAction");


module.exports = async function (params) {
    let districtIdList = await conn(`SELECT district_id AS districtId FROM district_file WHERE parent_id IN (?) AND delete_sign = 1 UNION SELECT district_id AS districtId FROM district_file WHERE parent_id IN (SELECT district_id AS parent_id FROM district_file WHERE parent_id IN (?) AND delete_sign = 1) AND delete_sign = 1`,[params.districtIds,params.districtIds])

    let delIdList = _.pluck(districtIdList,"districtId");
    delIdList = delIdList.concat(params.districtIds);
    await conn(`UPDATE district_file SET delete_sign = 2 WHERE district_id IN (?)`,[delIdList]);
    await operationRecord(params);
    return { success: true };
};
